<html>
<!-- 3 level master-detail report. -->
<style>
 {{{defaultstyle}}}
 body {margin: 20px 10px; }
 td, th {border: solid #eee 1px; font-size: 12px; padding: 2 2; }
 th {background: #888; color: white; padding: 5px 5px;  }
 .total td {border: none; border-top: solid #888 1px; font-weight: bold}
 .master {border: none; border-bottom: solid red 1px; font-size: 20px; color: #55c;}
 .items td {background: #fafaff; border-color: #dcdcfe}
 .sp {color: #aaa}
</style>

<h2>Customers  / Orders / Items</h2>

<DATAPACKET width="900" style="margin: 20 10 10 0">
 <METADATA>
  <FIELDS>
   <FIELD name="COMPANY" class="master" template="@CUSTNO@ #"/>
   <FIELD name="SUMM" class="master" align="right"/>
  </FIELDS>
  <SQL>
   select c.custno, c.company, sum(itemstotal) summ
   from customer c join orders o on o.custno=c.custno
   group by 1,2
   order by company
  </SQL>
 </METADATA>

 <DETAIL width="900">
 <METADATA>
  <FIELDS>
   <FIELD name="ORDERNO" caption="Order No" group_template="@COMPANY@" total="count(*)" width="10%"/>
   <FIELD name="SALEDATE" caption="Sale Date" width="10%"/>
   <FIELD name="SHIPDATE" caption="Ship Date" width="10%"/>
   <FIELD name="LASTNAME" caption="Employee" width="20%"/>
   <FIELD name="PAYMENTMETHOD" caption="Payment Method" align="center" width="20%"/>
   <FIELD name="ITEMSTOTAL" caption="Total" total="sum" format="# ### ###.00" width="15%"/>
   <FIELD name="AMOUNTPAID" caption="Amount Paid" total="sum" format="# ### ###.00" width="15%"/>
  </FIELDS>
  <SQL>
   select o.orderno, cast(saledate as date) saledate, cast(shipdate as date) shipdate,
    paymentmethod, itemstotal, amountpaid, e.lastname
   from orders o
   join employee e on e.empno=o.empno
   where custno=:custno
   order by 1
  </SQL>
 </METADATA>

  <DETAIL style="width: 300px; margin: 20 0 20 30;" class="items">
   <METADATA header="0">
    <FIELDS>
     <FIELD name="ITEMNO" caption="Item No" width="30%" template="<span class=sp>No</span> #"/>
     <FIELD name="PARTNO" caption="Part No" width="30%" template="<span class=sp>Part</span> #"/>
     <FIELD name="QTY" caption="Quantity" width="40%" template="<span class=sp>Qty</span> #" />
    </FIELDS>
    <SQL>
     select i.itemno, i.partno, qty
     from items i
     where orderno=:orderno
    </SQL>
   </METADATA>
  </DETAIL>

 </DETAIL>

</DATAPACKET>

</html>
